<?php
/**
 * 用户订阅列表
 * Created by PhpStorm.
 * User: andy
 * Date: 2019/11/19
 * Time: 下午6:42
 */

namespace app\common\model;

use think\Model;

class UserBookModel extends Model{

    protected $autoWriteTimestamp = true;

    /**
     * 增加
     * @param $data
     * @return array
     * @throws \think\exception\DbException
     */
    public function adds($data){

        if (empty($data['id'])) {
            $status = self::insertGetId($data);

            if ($status) {
                return ['status' => 1, 'msg' => '增加成功！',"id"=>$status];
            } else {
                return ['status' => 0, 'msg' => '增加失败！'];
            }
        } else {
            $status = self::save($data, ['id' => $data["id"]]);

            if ($status) {
                return ['status' => 1, 'msg' => '修改成功！'];
            } else {
                return ['status' => 0, 'msg' => '修改失败！'];
            }
        }
    }

    public function getUserBook($id,$uid){
        $where = [
            "id"=>$id,
            "user_id"=>$uid,
        ];
        $info = self::where($where)->find();
        return $info;
    }
} 